class syncLoopHook {
    event = {};

    constructor() {
        console.log('syncLoopHook');
    }

    tap(name, cb) {
        cb = typeof cb === 'function' ? cb : (...args) => args;
        this.event[name] = cb;
    }

    call(...args) {
        const events = Object.values(this.event);
        let index = 0;
        const getResult = (event, index, args) => {
            if (event[index] && event[index](args) !== undefined) {
                getResult(event, index, args);
            }
        }
        while (getResult(events, index, args) === undefined && index < events.length) {
            index++;
        }
    }
}

module.exports = syncLoopHook;